//
//  AppDelegate.m
//  体育商城
//
//  Created by  on 2022/9/23.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    bg_setDisableCloseDB(YES);
    NSString *account = [[NSUserDefaults standardUserDefaults] valueForKey:accountkey];
    if (account != nil && account.length > 0) {
        [UserTool find:account complete:^(User * _Nonnull user) {
            self.user = user;
        }];
    }else{
        [UserTool register:@"mm123" psw:@"123" complete:^(NSDictionary * _Nonnull dict) {}];
        self.user = [User new];
    }
    CGRect frame = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc] initWithFrame:frame];
    self.window.rootViewController = [[BaseTabBarViewController alloc] init];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)setUser:(User *)user{
    _user = user;
    if ([_user.account isEqualToString:@""]) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:accountkey];
    }else{
        [[NSUserDefaults standardUserDefaults] setValue:_user.account forKey:accountkey];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:notifyUserUpdate object:nil];
}


@end
